﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace 充电桩上位机.Model.Authorize;

public class LicenseGenerator
{
    public static string GetCpuId()
    {
        string cpuId = string.Empty;
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("select ProcessorId from Win32_Processor");
        foreach (ManagementObject obj in searcher.Get())
        {
            cpuId = obj["ProcessorId"].ToString();
            break; // 通常只需要第一个CPU信息
        }
        return cpuId;
    }

    // 获取主板信息（可以作为机器码的一部分）
    public static string GetMotherboardId()
    {
        string motherboardId = string.Empty;
        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard");
        foreach (ManagementObject obj in searcher.Get())
        {
            motherboardId = obj["SerialNumber"].ToString();
            break; // 只获取第一个主板
        }
        return motherboardId;
    }

    // 生成机器码（基于 CPU 和主板信息）
    public static string GenerateMachineCode()
    {
        string cpuId = GetCpuId();
        string motherboardId = GetMotherboardId();
        string machineCode = cpuId + motherboardId;  // 简单拼接为机器码

        return machineCode;
    }
}
